import pandas as pd
import matplotlib.pyplot as plt

# 设置中文字体和负号正常显示
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 读取数据
df = pd.read_csv('C:\\Users\\LENOVO\\Desktop\\数据可视化\\job_clean.csv', sep=',', header=None, names=[
    "id", "job_type", "job_title", "annual_salary", "company_type", "company_size", "city"
])

# 计算前十岗位
top_jobs = df.groupby('job_title')['annual_salary'].mean().sort_values(ascending=False).head(10)

# 绘制水平柱状图
plt.figure(figsize=(10, 6))
plt.barh(top_jobs.index[::-1], top_jobs.values[::-1], color='purple')
plt.title("平均薪资前十的岗位")
plt.xlabel("平均年薪")
plt.tight_layout()
plt.show()
